package cn.trip.biz.service.impl;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.ItripAreaDic;
import cn.itrip.beans.pojo.ItripLabelDic;
import cn.itrip.common.RedisUtil;
import cn.itrip.dao.ItripAreaDicMapper;
import cn.itrip.dao.ItripLabelDicMapper;
import cn.trip.biz.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("HotleService")
public class HotleServiceImpl implements HotelService {
    Dto dto = null;
    List itripAreaDicVOs = null;
    @Autowired
    private RedisUtil redisUtil;
    @Resource(name = "itripAreaDicMapper")
    private ItripAreaDicMapper itripAreaDicMapper;
    @Autowired
    private ItripLabelDicMapper itripLabelDicMapper;

    /**
     * 查询热门城市
     *
     * @param isChina 国内 1，国外 2
     * @return dto
     */
    @Override
    public Dto selectByisChina(Integer isChina) {
        List itripAreaDicVOs = new ArrayList();
        itripAreaDicVOs = new ArrayList();
        List<ItripAreaDic> list = null;
        if (redisUtil.get("AreaDic:" + isChina) == null) {
            if (isChina != null && !isChina.equals("")) {
                list = itripAreaDicMapper.selectByisChina(isChina);
                if (list != null) {
                    redisUtil.set("AreaDic:" + isChina, list, 600);
                } else {
                    dto = new Dto();
                    dto.setSuccess("false");
                    dto.setMsg("type不能为空");
                    return dto;
                }
            }
        } else {
            list = (List<ItripAreaDic>) redisUtil.get("AreaDic:" + isChina);
        }
        dto = new Dto();
        dto.setErrorCode("0");
        dto.setSuccess("true");
        dto.setMsg("显示成功");
        dto.setData(list);

        return dto;
    }

    /**
     * 查询酒店特色列表
     *
     * @param id
     * @return dto
     * @throws Exception
     */
    @Override
    public Dto selectByid(Long id) throws Exception {
        List<ItripLabelDic> LabelDicslist = null;
        if (redisUtil.get("special:" + id) == null) {
            LabelDicslist = itripLabelDicMapper.selectByid(id);

            redisUtil.set("special:" + id, LabelDicslist, 600);
        } else {
            LabelDicslist = (List<ItripLabelDic>) redisUtil.get("special:" + id);
        }
        dto = new Dto();
        dto.setErrorCode("0");
        dto.setSuccess("true");
        dto.setMsg("显示成功");
        dto.setData(LabelDicslist);

        return dto;
    }
}
